<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{
	padding: 0;
	margin: 0;
}
	#box{
		width: 800px;
		height: 500px;
		border: 4px solid blue;
		margin: 30px auto;
		position: relative;
	}
	#box img{
		margin-top: 50px;
		margin-left: 100px;
	}
</style>
<script type="text/javascript">
	window.onload = function(){
		var box = document.getElementById('box');
		var liuyan = document.getElementById('liuyan');

		//获得元素的位置
		// 如果该元素的父级元素没有定位属性，那么就参考body来获得位置
		var p = liuyan.offsetLeft;
		alert(p);
	}
</script>
</head>

<body>

<div id="box">
	<img src="liuyan.jpg" id="liuyan" />
</div>



</body>
</html>
